package com.zjy.heath_ms.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zjy.heath_ms.entity.QueryPageBean;
import com.zjy.heath_ms.entity.Result;
import com.zjy.heath_ms.pojo.Order;
import com.zjy.heath_ms.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.Objects;

/**
 * 项目名 heath_ms
 * 类名  OrderController 预约管理
 * 作者 lzq
 * 创建时间  2025/5/25 9:40
 */

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 查询预约信息
     * @param queryPageBean
     * @return
     */
    @GetMapping
    public Result getOrders(QueryPageBean queryPageBean) {
        Page<Order> page =orderService.findPage(queryPageBean);
        return Result.buildSuccess(page);
    }

    /**
     * 确认预约，并改变预约状态为已到诊
     * @param map
     * @return
     */

    @PutMapping("/visit")
    public Result visit(@RequestBody Map<String, Object> map) {
        Integer id = (Integer) map.get("id");
        return orderService.hasVisit(id)? Result.buildSuccess() : Result.buildFail();
    }

    /**
     * 删除预约信息
     */
    @DeleteMapping
    public Result delete(Integer id) {
        return orderService.removeById(id) ? Result.buildSuccess() : Result.buildFail();
    }
}

